package controller.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import dao.UserMessageTD;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.Account;
import pojo.message.imp.Message;
import service.SubmitMessage;
import util.Result;

import java.rmi.server.ExportException;
import java.util.*;

@Controller
@CrossOrigin
@ResponseBody
@RequestMapping("chat")
public class TaskProcessing {
    @Autowired
    private UserMessageTD userMessageTD;
    @RequestMapping("friends")
    public Result getFriendsList(@RequestBody Account account){
//        System.out.println(account.getId());
        List<String> list=new ArrayList<>();
        try{
            list=userMessageTD.getFriendsList(account.getId());
        }catch (Exception e){
            System.out.println(e);
        }
        return Result.success(list.toString());
    }
    @RequestMapping("message")
    public Result getMessage(@RequestBody ArrayList<Account> account){
        System.out.println(account);
        String id_=account.get(0).getId();
        String id_f=account.get(1).getId();
        List<Message> list= SubmitMessage.getMessageForId(id_,id_f);
        return Result.success(JSON.toJSONString(list));
    }
}
